package com.cbd.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @Author: CBD
 * @Date: 2024/11/14 11:29
 * @Description:RabbitMQ配置
 */
@Configuration
public class RabbitMQConfig {
    //创建队列
    @Bean
    public Queue myQueue() {
        //参数1：队列名称，参数2：是否持久化
        return new Queue("opQueue", true);
    }
    @Bean
    //创建主题类型交换机
    public TopicExchange myExchange() {
        //参数1：交换机名称
        return new TopicExchange("opExchange");
    }

    //绑定队列到交换机
    @Bean
    public Binding binding() {
        //参数1：队列，参数二：交换机，参数：路由键
        return BindingBuilder.bind(myQueue()).to(myExchange()).with("opRoutingKey");
    }
}
